Page({
  data: {
    searchValue: '',
    doctors: [
      { name: '张医生', title: '主任医师', department: '消化内科' },
      { name: '李医生', title: '副主任医师', department: '心血管内科' },
      { name: '王医生', title: '主治医师', department: '神经内科' },
      { name: '刘医生', title: '主任医师', department: '呼吸内科' },
      { name: '陈医生', title: '副主任医师', department: '内分泌科' }
    ],
    filteredDoctors: []
  },

  onLoad() {
    // 初始化显示所有医生
    this.setData({
      filteredDoctors: this.data.doctors
    });
  },

  onSearchChange(e) {
    const searchValue = e.detail;
    this.setData({
      searchValue
    });
    
    // 根据搜索值筛选医生
    const filteredDoctors = this.data.doctors.filter(doc => 
      doc.name.toLowerCase().includes(searchValue.toLowerCase()) ||
      doc.title.toLowerCase().includes(searchValue.toLowerCase()) ||
      doc.department.toLowerCase().includes(searchValue.toLowerCase())
    );
    
    this.setData({
      filteredDoctors
    });
  },

  selectDoctor(e) {
    const doctor = e.currentTarget.dataset.doctor;
    wx.setStorageSync('selectedDoctor', doctor.name);
    
    // 返回上一页并更新数据
    const pages = getCurrentPages();
    const prevPage = pages[pages.length - 2];
    prevPage.setData({
      doctor: doctor.name
    });
    
    wx.navigateBack();
  }
}); 